﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace BDSim
{
    /// <summary>
    /// 钟差参数  （Add by lhz）
    /// </summary>
    public struct ClockErrParam
    {
        /// <summary>
        /// 钟差参数的参考时刻
        /// </summary>
        public UTCTime t0;

        /// <summary>
        /// 初始钟差 （设置参数，偏差	：1e-4，绝对值＜10-3s）
        /// </summary>
        public double b0;

        /// <summary>
        /// 初始频移 （设置参数，漂移速度：1e-9，绝对值＜10-9s/s）
        /// </summary>
        public double d0;

        /// <summary>
        /// 老化率   （设置参数，漂移率：1e-18，绝对值＜10-15s/s2）
        /// </summary>
        public double r0;

        /// <summary>
        /// 随机噪声量级（绝对值＜2×10-9s）
        /// </summary>
        public double RandomNoise_H;
    }
   

    /// <summary>
    /// 导航电文中钟差参数拟合系数
    /// </summary>
    public struct ClkErrFitMsg
    {
        public UTCTime FitTime;

        /// <summary>
        /// 参考时间
        /// </summary>
        public double toc;

        /// <summary>
        /// 钟差
        /// </summary>
        public double a0;

        /// <summary>
        /// 钟速
        /// </summary>
        public double a1;

        /// <summary>
        /// 钟漂
        /// </summary>
        public double a2;
    };


    /// <summary>
    /// 钟差输出数据
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct AtomicClockErr
    {
        /// <summary>
        /// 当前整步点计数
        /// </summary>
        public double m_TimeId;

        /// <summary>
        /// 采样时间间隔（步长）
        /// </summary>
        public double m_step;

        /// <summary>
        /// 前二整步点钟差（单位：秒）
        /// </summary>
        public double m_sb2;

        /// <summary>
        /// 前一整步点钟差（单位：秒）
        /// </summary>
        public double m_sb1;

        /// <summary>
        /// 当前整步点钟差（单位：秒）
        /// </summary>
        public double m_s0;

        /// <summary>
        /// 后一整步点钟差（单位：秒）
        /// </summary>
        public double m_sa1;

        /// <summary>
        /// 后二整步点钟差（单位：秒）
        /// </summary>
        public double m_sa2;
    };

    ///// <summary>
    ///// 钟差拟合参数
    ///// </summary>
    //public struct clkErrParam
    //{
    //    public double a0;
    //    public double a1;
    //    public double a2;
    //};

    /// <summary>
    /// 钟差仿真数据存储
    /// </summary>
    public struct ClkSimData
    {
        /// <summary>
        /// 编号
        /// </summary>
        public int ID;

        /// <summary>
        /// 名称
        /// </summary>
        public string Name;
        /// <summary>
        /// 仿真时间
        /// </summary>
        public UTCTime SimTime;

        /// <summary>
        /// 钟差数据
        /// </summary>
        public double ClkError;
    }

    /// <summary>
    /// 钟差拟合参数结构体（存储数据集使用）
    /// </summary>
    //public struct ClkErrFitMsg
    //{
    //    public UTCTime FitTime;
    //    public double a0;
    //    public double a1;
    //    public double a2;
    //};

    #region 钟差动态库增加结构体

    /// <summary>
    /// 原子钟相关属性
    /// </summary>
    public struct AtomicClock
    {
        /// <summary>
        /// 初始钟差     设置参数，偏差		1e-4
        /// </summary>
        public double m_b0;

        /// <summary>
        /// 初始频移     设置参数，漂移速度	1e-9 
        /// </summary>
        public double m_d0;

        /// <summary>
        /// 老化率       设置参数，漂移率		1e-18
        /// </summary>
        public double m_a;

        /// <summary>
        /// 采样间隔(单位:秒)		采样间隔影响钟差的噪声属性，所以写入原子钟的原始属性
        /// </summary>
        public double m_tao;

        /// <summary>
        /// allan方差	   //////----------------目前没用到
        /// </summary>
        public double m_allan;

        /// <summary>
        /// 噪声强度
        /// </summary>
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
        public double[] m_H;

    }
    
    /// <summary>
    /// 钟差计算模型
    /// </summary>
    public struct ClkErr_Input
    {
        /// <summary>
        /// 时间计数
        /// </summary>
        public double TimeId;

        /// <summary>
        /// [MAX_SAT_NUM]
        /// </summary>
        public AtomicClock clk;

        /// <summary>
        /// 1表示白噪声  5表示5噪声
        /// </summary>
        public int addNoise;

        /// <summary>
        /// 噪声强度（白噪声）
        /// </summary>
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
        public double[] H;
    }

    public struct ClkErr_Output
    {
        /// <summary>
        ///[MAX_SAT_NUM]; 
        /// </summary>
        public AtomicClockErr clkerr;
    }

    /// <summary>
    /// 钟差插值模型
    /// </summary>
    public struct ClkTrp_Input
    {
        public double tobs;

        /// <summary>
        /// m_TimeId; tao; m_sb2; m_sb1; m_s0; m_sa1; m_sa2;
        /// </summary>
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 7)]
        public double[] a;
    }

    public struct ClkTrp_Param
    {
        /// <summary>
        /// 钟差计算开关，0=不考虑钟差，1=考虑钟差
        /// </summary>
        public int Iclo;
    }

    public struct ClkTrp_Output
    {
        public double DeltClock;
    }
    #endregion
}
